# 用新的数据finetune florence large
# 同样的包含OCR（中文，英文），CAP任务

PROMPT_VERSION=plain
MODEL_VERSION=florence2


# num_gpus=$(nvidia-smi -L | wc -l)

export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
num_gpus=8


# 我也不知道为什么这个无法在A100上工作
# A100只能用dist.sh

# ./data/sft/inhouse_books.json \
                # ./data/sft/inhouse_cn_gen1.json \

# Florence large model used 1e-5, we using 1e-5 here, 3072 batchsize
# warmup using linear for 5000 steps
#     --warmup_ratio 0.03 \  

# 基本上能学到中文OCR能力，接下来就是scaleup
# 训练2个epoch

#                 ./data/sft/curate_ocr_b2.json \

# 新增9w的中文ocr数据，来自Wanjuan

#                 
#                 ./data/sft/llava_recap_cc3m.json \

#  

# deepspeed vision_pretrain/pretrain_flr2.py \
#     --deepspeed ./scripts/vision_pretrain/zero2.json \

# looks like we need train at least 4 epochs

#                 ./data/sft/synthdog_cn.json \
#                 ./data/sft/synthdog_en.json \

    # --warmup_steps 500 \

# ./data/sft/my_ja_ocr_b1.json \
#                 ./data/sft/laion2b_ja_ocr.json \

#                 ./data/sft/sharegpt4v_mini_pretrain.json \

                # ./data/sft/llavar_pretrain.json \

# 在后面几个阶段加入日语的数据？还有韩语的数据需要制作一下
# 就不信，做不到识别日语和韩

torchrun --nproc-per-node=$num_gpus --master-port 2365 vision_pretrain/pretrain_flr2.py \
    --model_name_or_path ./checkpoints/Florence-2-large \
    --version $PROMPT_VERSION \
    --data_path ./data/sft/curate_ocr_b1.json \
                ./data/sft/curate_ocr_b2.json \
                ./data/sft/inhouse_crop_b1.json \
                ./data/sft/allava_laion.json \
                ./data/sft/icdar2019_lsvt_50k_ocr.json \
                ./data/sft/icdar_mlt_ocr.json \
                ./data/sft/mtwi_ocr_20k.json \
                ./data/sft/autoposter_76k_ocr.json \
                ./data/sft/wukong_ocr_b1.json \
                ./data/sft/wukong_ocr_b2.json \
                ./data/sft/wukong_ocr_b3.json \
                ./data/sft/wanjuan_ocr_b1.json \
                ./data/sft/wanjuan_ocr_b2.json \
                ./data/sft/wanjuan_ocr_b3.json \
                ./data/sft/mmc.json \
                ./data/sft/llava_recap_cc3m.json \
                ./data/sft/share-captioner_coco_lcs_sam_1246k_1107.json \
                ./data/sft/minigemini_pretrain.json \
                ./data/sft/my_ja_ocr_b1.json \
                ./data/sft/laion2b_ja_ocr.json \
    --image_folder ./data/images_all \
    --group_by_modality_length True \
    --output_dir ./checkpoints/$MODEL_VERSION-ft-mine-4e \
    --num_train_epochs 5 \
    --per_device_train_batch_size 8 \
    --per_device_eval_batch_size 4 \
    --gradient_accumulation_steps 48 \
    --evaluation_strategy "no" \
    --save_strategy "steps" \
    --save_steps 500 \
    --save_total_limit 1 \
    --learning_rate 1e-5 \
    --weight_decay 0. \
    --warmup_steps 300 \
    --lr_scheduler_type "cosine" \
    --logging_steps 1 \
    --tf32 True \
    --fp16 False \
    --bf16 True \
    --model_max_length 1024 \
    --gradient_checkpointing True \
    --dataloader_num_workers 4 \
    --lazy_preprocess True